<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    body {margin: 0;overflow: hidden;}
    #canvas {background-color: antiquewhite;}
  </style>
</head>
<body>
  <canvas id="canvas"></canvas>
  <script>
    /** @type {HTMLCanvasElement} */
    const canvas = document.querySelector('#canvas');
    canvas.width = window.innerWidth;
    canvas.height = window.innerHeight;
    const ctx = canvas.getContext('2d');

    ctx.beginPath();
    ctx.strokeStyle = '#999';
    ctx.setLineDash([8]);
    ctx.moveTo(30,200);
    ctx.lineTo(700,200);
    ctx.stroke();

    /* font设置 */
    ctx.font = '24px Arial';

    /*
      textBaseline: 垂直对齐方式
      alohabetic: 默认。标准字幕基线对齐。
      top: 上对齐
      hanging: 悬挂基线对齐
      middle: 垂直居中
      ideographic: 表意基线对齐
      bottom: 下对齐
    */
    ctx.textBaseline = 'top';
    ctx.fillText('HELLO', 50, 200);

    ctx.textBaseline = 'middle';
    ctx.fillText('HELLO', 150, 200);

    ctx.textBaseline = 'bottom';
    ctx.fillText('HELLO', 250, 200);

    ctx.textBaseline = 'hanging';
    ctx.fillText('HELLO', 350, 200);

    ctx.textBaseline = 'ideographic';
    ctx.fillText('HELLO', 450, 200);

    ctx.textBaseline = 'alohabetic';
    ctx.fillText('HELLO', 550, 200);


  </script>
</body>
</html>